package ginRoute

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
	"utilsx/entity"
)

func SuccessWithData(ctx *gin.Context, data any) {
	if data == nil {
		data = gin.H{}
	}
	res := entity.Response[any]{
		Code: http.StatusOK,
		Data: data,
	}
	ctx.JSON(http.StatusOK, res)
	ctx.Abort()
}
func ErrorWithDetail(ctx *gin.Context, code int, msgKey string, err error) {
	res := entity.Response[any]{
		Code:    code,
		Message: msgKey + fmt.Sprintf(":Err:%v", err),
	}
	ctx.JSON(http.StatusOK, res)
	ctx.Abort()
}
